//
//  ViewController.swift
//  TestIOS
//
//  Created by yangentao on 2021/2/9.
//
//

import UIKit
import SwiftSweet

class ViewController: UIViewController {
    lazy var label: UILabel = NamedView(self, "label")

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .green
        view += LinearLayout(.vertical).apply { ll in
            ll.constraints { c in
                c.center.eqParent()
                c.width.eqParent().constant(-20)
                c.height.eq(self:.width)
            }
            ll.backgroundColor = .blue
            ll.addView(UIView(frame: .zero)) { v in
                v.linearParams { p in
                    p.widthMatch()
                    p.height = 50
                    p.gravityY = .center
                }
                v.backgroundColor = .red
            }
            ll += UILabel(frame: .zero).apply { lb in
                lb.named("label")
                lb.textAlignment = .center
                lb.text = "Hello"
                lb.backgroundColor = .yellow
                lb.textColor = .red
                lb.linearParams { p in
                    p.sizeWrap()
//                    p.gravityX = .center
//                    p.gravityY = .center
//                    p.weight = 1
                }
//                lb.keepContent(.horizontal)
            }
        }
        //(10000.0, 10000.0) (0.0, 0.0)
//        logd( UIView.layoutFittingExpandedSize, UIView.layoutFittingCompressedSize)

    }

    func test1() {
        view.linearVer { ll in
            ll.constraints { cb in
                cb.centerY.eqParent()
                cb.edgeX.eqParent()
                cb.height.eq(400)
            }
            ll.defaultGravityY = .top
            ll.backgroundColor = .green
            ll.imageView { iv in
                iv.linearParams { p in
                    p.width = 80
                    p.height = 80
                    p.gravityX = .center
                }
                iv.image = UIImage(named: "logo")
                iv.backgroundColor = .red
            }
            ll.labelX { lb in
                lb.linearParams { p in
                    p.widthWrap()
                    p.height = 30
                    p.gravityX = .center
                    p.gravityY = .top
                }
                lb.text = "Hello"
                lb.backgroundColor = .blue
            }

//            ll.imageView { iv in
//                iv.image = UIImage(named: "logo")?.resizingMode
//            }

        }
    }


}
